package com.greendao.dao;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;

import com.hegongda.money.start.bean.AnswerItemListConverter;
import java.util.List;

import com.hegongda.money.start.bean.AdviceBean;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "ADVICE_BEAN".
*/
public class AdviceBeanDao extends AbstractDao<AdviceBean, String> {

    public static final String TABLENAME = "ADVICE_BEAN";

    /**
     * Properties of entity AdviceBean.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property TypeId = new Property(0, String.class, "typeId", true, "TYPE_ID");
        public final static Property Name = new Property(1, String.class, "name", false, "NAME");
        public final static Property Road = new Property(2, String.class, "road", false, "ROAD");
        public final static Property Adress = new Property(3, String.class, "adress", false, "ADRESS");
        public final static Property Area = new Property(4, String.class, "area", false, "AREA");
        public final static Property IsOpen = new Property(5, boolean.class, "isOpen", false, "IS_OPEN");
        public final static Property ComputerList = new Property(6, String.class, "computerList", false, "COMPUTER_LIST");
    }

    private final AnswerItemListConverter computerListConverter = new AnswerItemListConverter();

    public AdviceBeanDao(DaoConfig config) {
        super(config);
    }
    
    public AdviceBeanDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"ADVICE_BEAN\" (" + //
                "\"TYPE_ID\" TEXT PRIMARY KEY NOT NULL ," + // 0: typeId
                "\"NAME\" TEXT," + // 1: name
                "\"ROAD\" TEXT," + // 2: road
                "\"ADRESS\" TEXT," + // 3: adress
                "\"AREA\" TEXT," + // 4: area
                "\"IS_OPEN\" INTEGER NOT NULL ," + // 5: isOpen
                "\"COMPUTER_LIST\" TEXT);"); // 6: computerList
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"ADVICE_BEAN\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, AdviceBean entity) {
        stmt.clearBindings();
 
        String typeId = entity.getTypeId();
        if (typeId != null) {
            stmt.bindString(1, typeId);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(2, name);
        }
 
        String road = entity.getRoad();
        if (road != null) {
            stmt.bindString(3, road);
        }
 
        String adress = entity.getAdress();
        if (adress != null) {
            stmt.bindString(4, adress);
        }
 
        String area = entity.getArea();
        if (area != null) {
            stmt.bindString(5, area);
        }
        stmt.bindLong(6, entity.getIsOpen() ? 1L: 0L);
 
        List computerList = entity.getComputerList();
        if (computerList != null) {
            stmt.bindString(7, computerListConverter.convertToDatabaseValue(computerList));
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, AdviceBean entity) {
        stmt.clearBindings();
 
        String typeId = entity.getTypeId();
        if (typeId != null) {
            stmt.bindString(1, typeId);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(2, name);
        }
 
        String road = entity.getRoad();
        if (road != null) {
            stmt.bindString(3, road);
        }
 
        String adress = entity.getAdress();
        if (adress != null) {
            stmt.bindString(4, adress);
        }
 
        String area = entity.getArea();
        if (area != null) {
            stmt.bindString(5, area);
        }
        stmt.bindLong(6, entity.getIsOpen() ? 1L: 0L);
 
        List computerList = entity.getComputerList();
        if (computerList != null) {
            stmt.bindString(7, computerListConverter.convertToDatabaseValue(computerList));
        }
    }

    @Override
    public String readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0);
    }    

    @Override
    public AdviceBean readEntity(Cursor cursor, int offset) {
        AdviceBean entity = new AdviceBean( //
            cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // typeId
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // name
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // road
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // adress
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // area
            cursor.getShort(offset + 5) != 0, // isOpen
            cursor.isNull(offset + 6) ? null : computerListConverter.convertToEntityProperty(cursor.getString(offset + 6)) // computerList
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, AdviceBean entity, int offset) {
        entity.setTypeId(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
        entity.setName(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setRoad(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setAdress(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setArea(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setIsOpen(cursor.getShort(offset + 5) != 0);
        entity.setComputerList(cursor.isNull(offset + 6) ? null : computerListConverter.convertToEntityProperty(cursor.getString(offset + 6)));
     }
    
    @Override
    protected final String updateKeyAfterInsert(AdviceBean entity, long rowId) {
        return entity.getTypeId();
    }
    
    @Override
    public String getKey(AdviceBean entity) {
        if(entity != null) {
            return entity.getTypeId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(AdviceBean entity) {
        return entity.getTypeId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
}
